<script>

$('#ajax_form').ajaxForm({beforeSubmit: before,success: processJson });

function before() {
    $('.ui-dialog-buttonpane button').hide()
    $('#dialog').addClass('ui-state-disabled')
}


function processJson(data) {
	
   

    //fix para cuando subimos archivos en formulario
    if(!jQuery.isPlainObject(data)){
        
        if(data.substr(0,5)=='<pre>')
        {
            var aux = data.replace(/<\/?pre>/g, "");
            
            aux = aux.replace(/&lt;/g, "<");
            aux = aux.replace(/&gt;/g, ">");
    
            
            var data = jQuery.parseJSON(aux);
        }
    }
    
    if(data.status=='reload')
	{
	   location.reload();
       return true;
    }
    
        
    if(data.status=='debug')
	{
       return true;
    }
    
    if(data.status=='close')
	{
       $("#dialog").dialog('close');
    }
    
    if(data.status=='ok')
	{
		$("#dialog").dialog('close');
		<?php if($this->actionName=='insertar'):?>
			$('#<?=$this->id_tablesorter?> tbody').prepend(data.fila);
    		$('#<?=$this->id_tablesorter?> tbody tr').filter(":first").effect('highlight',3000);
    		
    		$('.utileditar').filter(":first").button({
		            text: false,
		            icons: {
		                primary: "ui-icon-pencil"
		            }
		    });	
		    $('.utildelete').filter(":first").button({
		            text: false,
		            icons: {
		                primary: "ui-icon-trash"
		            }
		    });
		   
    	<?php else:?>
    		$('#<?=$this->id_tablesorter?> .tr_<?php echo $this->id;?>').replaceWith(data.fila);
    		$('#<?=$this->id_tablesorter?> .tr_<?php echo $this->id;?>').effect('highlight',3000);
    		
    		$("#<?=$this->id_tablesorter?> .tr_<?php echo $this->id;?> .utileditar").button({
		            text: false,
		            icons: {
		                primary: "ui-icon-pencil"
		            }
		    });	
		    $("#<?=$this->id_tablesorter?> .tr_<?php echo $this->id;?> .utildelete").button({
		            text: false,
		            icons: {
		                primary: "ui-icon-trash"
		            }
		    });
    		
    	<?php endif?>
    	
    	$("div.botones").buttonset().css('width','50px');
	}
	else
	{
		$('#dialog').html(data)
        
	}
    
    $('.ui-dialog-buttonpane button').show() 
    $('#dialog').removeClass('ui-state-disabled')
}


$(document).ready(function(){ 
    $('.fecha').datepicker();
    <?=$this->onready?>
})


</script>